package com.ny.dao.lmpl;

import com.ny.dao.OrderDao;
import com.ny.entity.Order;
import com.ny.until.SqlConncetion;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class OrderDaoImpl implements OrderDao {
 private  SqlConncetion  sqlConncetion=new SqlConncetion();

    public OrderDaoImpl() throws SQLException, ClassNotFoundException {
        sqlConncetion.getConnection();
    }

    @Override
    public int addOrder(Order order) throws SQLException, ClassNotFoundException {
        String sql = "insert into orders(student_id,product_id,number,total_price)  values(?,?,?,?)";
        PreparedStatement  preparedStatement = sqlConncetion.getConnection().prepareStatement(sql);
        preparedStatement.setInt(1, order.getStudentId());
        preparedStatement.setInt(2,order.getStudentId());
        preparedStatement.setInt(3,order.getNumber());
        preparedStatement.setDouble(4,order.getTotalPrice());

        return preparedStatement.executeUpdate();
    }
}
